package com.example.demo.service;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelReader;
import com.example.demo.config.StringExcelListener;
import com.example.demo.mapper.StudentMapper;
import com.example.demo.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

@Service
public class AddExcel {


    @Autowired
    private StudentMapper studentMapper;



    public List<Student> getAll(){
        return studentMapper.getAll();
    }


    public Integer updateStudent(Student student){
        return studentMapper.updateStudent(student);
    }


    public Integer insertStudent(Student student){
        return studentMapper.insertStudent(student);
    }


    /**
     * 根据excel输入流，读取excel文件
     *
     * @param inputStream exece表格的输入流
     * @return 返回双重list的集合
     **/
    public List<List<String>> writeWithoutHead(InputStream inputStream) {
        StringExcelListener listener = new StringExcelListener();
        ExcelReader excelReader = EasyExcelFactory.read(inputStream, null, listener).headRowNumber(0).build();
        excelReader.read();
        List<List<String>> datas = listener.getDatas();
        excelReader.finish();
        return datas;
    }



}
